Skip to content

fix(studio): the edit bench reads a sealed preview through its editing port - #8010

Merged
miguel-heygen merged 6 commits into
mainfrom
test/edit-accuracy-port-sampler
Nov 17, 2026
Merged

miguel-heygen merged 6 commits into
mainfrom
test/edit-accuracy-port-sampler

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

The edit-accuracy bench's frame sampler reads the dragged element through the preview's editing port, not by reaching into the preview frame's document. With Studio's opaque-origin preview on (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=true), the bench can measure teleport again.

Why

The sampler found the element by reading contentWindow.location and document of each preview frame. An opaque-origin preview refuses those reads, so every frame was dropped, the sampler found no element, and teleport failed on every case, whatever Studio actually drew. The wait for a manual-edit gesture to finish (sequences.mjs) read the same document, so on an opaque preview it passed without waiting.

How

This builds on #8052, which adds the watch-geometry request: a preview pushes the named elements' geometry once per frame, measured in its ResizeObserver step (just before paint) and stamped with performance.timeOrigin + performance.now().

  • teleport.mjs: the page script opens an editing port of its own to each preview frame (the same editing-connect handshake createEditingPortClient uses). It asks query for the element and the composition root once, then watch-geometry for both. Every push becomes one sample, paired by its own stamp with what this page showed at that moment. The top page keeps two short histories on the same clock: the pointer (from its pointer events), and Studio's crop and press-waiting outlines (read each frame). A late push is never scored against a later pointer or a later outline, which is the pairing the direct read gets for free by reading both in one paint.
  • Pushes are dropped when they cannot belong to the current drag:
    • ones stamped before the drag started;
    • ones that land between a re-watch and its reply (port messages keep their order, so they belong to the previous watch);
    • for the next drag's element, every push from the moment the selector changes;
    • ones from a preview painted before it became the one on screen;
    • ones whose box is not finite.
  • Recording a drag starts only once a frame has measured the element (capped at 3 s), so the first sample is before the press, as the direct read's is. The scorer anchors every later sample on it. A first sample taken mid-drag can land on a frame where Studio's crop outline trails the pointer by a frame, and that offset then shows up on every later frame.
  • A shown, larger preview with no port yet leaves the frame unmeasured, rather than scoring a smaller preview's element.
  • Recording stops by sending each watch an empty list.
  • The element's border-box size still comes from computed-styles, the latest reply. It only scales clip-path insets, and every sequence case passes with it.
  • Studio's own client and the bench can share a port. The bench listens with addEventListener, leaves onmessage alone, and starts its request ids at 1e9.
  • sequences.mjs: the manual-edit wait asks each preview over the port; a preview that cannot answer yet counts as not clear.
  • The page script cannot import createEditingPortClient (it is a string run through evaluateOnNewDocument), so it keeps a small client of its own.

Test plan

  • fails without the fix: teleport.test.mjs. On main's teleport.mjs, 7 of its tests fail, starting with "measures the element from the preview's pushes, in top-frame px, and Studio keeps the shared port". The test preview's document and location throw, as a cross-origin frame's do, and it answers only over a real MessageChannel. On this branch, all 29 tests pass 3 runs in a row.

  • Each rule, removed from teleport.mjs one at a time, fails a test:

    • pointer read when the push lands, not at its stamp;
    • no drag-start cut;
    • no preview-swap cut;
    • no confirmed-watch gate;
    • no finite check;
    • no unwatch;
    • a larger port-less preview ignored;
    • outlines read when the push lands;
    • recording started before a frame has measured the element.
  • All 13 edit-accuracy unit test files pass. oxfmt and oxlint are clean.

  • Bench, every crop case at r0-root-z100 (24 cases), unsealed: tracking and teleport 24/24 in each of 3 runs. Without the measured-frame wait, 2 or 3 of 4 cases failed by one 2 px pointer step, where main's harness passed 4/4 in 3 runs on the same build.

  • Bench, every sequence case (--grid pr --filter '^seq', 73 cases), unsealed build, against main's harness on the same build:

    tracking press teleport drop reload render keys
    main's harness 73/73 73/73 73/73 73/73 73/73 73/73 73/73
    this branch 73/73 73/73 73/73 73/73 73/73 73/73 73/73

    undo is 73/73 on both in this run.

  • undo: the seqplainkeys cases fail undo now and then on both harnesses on the same build. The undo itself lands with the right bytes, but the box read just after it is about 240-312 px off. Across the other runs, main's harness failed it in 1 of 2 and this branch in 2 of 4. That flake predates this change and gets its own fix.

  • Sealed build (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=true), one build at this PR's base, the 32 cases of the seqresize, seqab, sequndo, seqheldtwice, seqplainkeys and seqinflight sequences. Each harness ran twice:

    check main run 1 main run 2 branch run 1 branch run 2
    tracking 20/32 18/32 20/32 21/32
    press 22/32 22/32 24/32 21/32
    teleport 0/32 0/32 19/32 19/32
    drop 24/32 24/32 24/32 24/32
    reload 24/32 24/32 24/32 24/32
    undo 20/32 20/32 21/32 19/32
    keys 26/32 26/32 26/32 26/32

    Main's harness can't measure teleport on a sealed preview at all. Every other check reads the element through Playwright's element handles, which this PR doesn't change; they vary by a case or two between runs on both harnesses. Each case where this branch fails teleport, next to the handle-read checks that fail in the same case:

    case branch teleport (run 1, run 2) branch's own failing handle-read checks, same run (run 1; run 2) main's failing handle-read checks (run 1; run 2)
    seqheldtwice-tlhold-px-r0-nested-z100 fail, fail tracking, drop, reload, undo; drop, reload, undo drop, reload, undo; drop, reload, undo
    seqheldtwice-tlhold-px-r0-root-z100 fail, fail drop, reload, undo; drop, reload, undo drop, reload, undo; drop, reload, undo
    seqplainkeys-none-center-r0-nested-z100 ERROR, ERROR ERROR: save 3 never landed; ERROR: save 3 never landed ERROR: save 3 never landed; ERROR: save 3 never landed
    seqplainkeys-none-center-r0-root-z100 ERROR, ERROR ERROR: save 3 never landed; ERROR: save 3 never landed ERROR: save 3 never landed; ERROR: save 3 never landed
    seqplainkeys-none-pct-r0-nested-z100 ERROR, ERROR ERROR: save 3 never landed; ERROR: save 3 never landed ERROR: save 3 never landed; ERROR: save 3 never landed
    seqplainkeys-none-pct-r0-root-z100 ERROR, ERROR ERROR: save 3 never landed; ERROR: save 3 never landed ERROR: save 3 never landed; ERROR: save 3 never landed
    seqplainkeys-none-px-r0-nested-z100 ERROR, ERROR ERROR: save 3 never landed; ERROR: save 3 never landed ERROR: save 3 never landed; ERROR: save 3 never landed
    seqplainkeys-none-px-r0-root-z100 ERROR, ERROR ERROR: save 3 never landed; ERROR: save 3 never landed ERROR: save 3 never landed; ERROR: save 3 never landed
    seqresize-none-center-r0-root-z100 fail, pass tracking; - none; none
    seqresize-none-pct-r0-nested-z100 fail, pass tracking; - none; tracking
    seqresize-none-px-r0-root-z100 fail, pass tracking; - none; none
    sequndo-none-center-r0-nested-z100 pass, fail -; tracking, press, undo tracking, press, undo; tracking, press, undo
    sequndo-none-center-r0-root-z100 pass, fail -; tracking, press, undo tracking; tracking, press, undo
    sequndo-none-pct-r0-nested-z100 pass, fail -; tracking, press, undo tracking, press, undo; tracking, press, undo
    sequndo-none-pct-r0-root-z100 pass, fail -; tracking, press, undo tracking, press, undo; tracking, press, undo
    sequndo-none-px-r0-nested-z100 fail, fail tracking, press, undo; tracking, press, undo none; none
    sequndo-none-px-r0-root-z100 fail, pass tracking, press, undo; - tracking, press, undo; tracking

    Every teleport failure here falls in a case and run where the branch's own handle reads also fail, so none of them is the sampler's alone. Those failures happen on main's harness too, on the sealed build only (every sequence case passes unsealed):

    • A drag at a seeked time with auto-keyframe on is never saved ("save 3 never landed").
    • After an undo, the next drag doesn't move the element; it stays 248 px from the pointer.
    • In seqheldtwice, drop, reload and undo fail.
    • Resize tracking fails now and then.

    Those are separate fixes in Studio's sealed preview, not this PR's.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 61 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

@miguel-heygen
miguel-heygen force-pushed the test/edit-accuracy-port-sampler branch 2 times, most recently from 793ba9e to acde455 Compare November 17, 2026 12:31
@miguel-heygen
miguel-heygen force-pushed the test/edit-accuracy-port-sampler branch from acde455 to 37b8e38 Compare November 17, 2026 12:58

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 37b8e38. No blockers.

Scope: three bench files under studio/tests/e2e/edit-accuracy/ (teleport.mjs, sequences.mjs, teleport.test.mjs). No shipped code changes.

No new port surface: the bench only uses request kinds that already exist (query, watch-geometry, computed-styles) through the existing editingAgent parsers, and core's isGeometry already checks the geometry replies. There are no bench-only port requests to gate. The bench's request ids start at 1e9, so they can't collide with Studio's.

Measurement: for unsealed previews the bench measures the same thing as before. Only the read path changes: geometry now arrives as port pushes, each paired with the pointer by its own timestamp. The gate job at head reports "accurate 267 (base branch 267)", which matches the body.

Verified:

  • All 13 edit-accuracy test files pass, 116/116.
  • With main's teleport.mjs under this PR's tests, 8 of 29 fail. That's one more than the body's "7", but the count is only cosmetic.
  • CI: 0 failed, cancelled or pending. All 15 edit-accuracy shards and the gate are green.

Nit (non-blocking): watches are tracked per port. If Studio ever watches geometry on its own port, the bench's rec.unwatch() in stopFrames would silently replace that watch. A comment there would help.

Need from author: nothing.
— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 5f8b7a6 Nov 17, 2026
129 checks passed
@miguel-heygen
miguel-heygen deleted the test/edit-accuracy-port-sampler branch November 17, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants